package com.yanqu.road.server.channelserver.cmd.activity.washe.jinbiao;

import com.yanqu.road.entity.activity.washe.data.WasheUserKey;
import com.yanqu.road.logic.pb.WashePb2;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.WasheProto;
import com.yanqu.road.server.channelserver.cmd.ChannelCommand;
import com.yanqu.road.server.channelserver.logic.ChannelMessageHelper;
import com.yanqu.road.server.channelserver.manager.activity.washe.ChannelWasheActivity;
import com.yanqu.road.server.channelserver.manager.activity.washe.ChannelWasheMgr;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.protocol.ChannelProtocol;
import com.yanqu.road.server.protocol.ClientProtocol;

import java.util.List;

@Cmd(code = ChannelProtocol.N_WASHE_GET_STAGE_REWARD_INFO, desc = "")
public class ChannelWasheGetStageRewardInfoCmd extends ChannelCommand {

    private WasheUserKey userKey;

    private List<Integer> hadRewardStageList;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        WasheProto.ChannelWasheGetStageRewardInfoReqMsg reqMsg = WasheProto.ChannelWasheGetStageRewardInfoReqMsg.parseFrom(packet.getBytes());
        userKey = WashePb2.parseWasheUserKey(reqMsg.getUserKey());
        hadRewardStageList = reqMsg.getHadRewardStageList();
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        ChannelWasheActivity activity = ChannelWasheMgr.getActivity(userKey.getChannelId());
        if (activity == null) {
            log.error("can not find washe activity! channelId {}.", userKey.getChannelId());
            return ;
        }
        ret = activity.getJinBiaoScoreStageRewardInfo(userKey, hadRewardStageList);
    }

    @Override
    public void sendData() {
        if (ret != 0) {
            WasheProto.WasheJinBiaoScoreStageRewardInfoRespMsg.Builder builder = WasheProto.WasheJinBiaoScoreStageRewardInfoRespMsg.newBuilder();
            builder.setRet(ret);
            ChannelMessageHelper.sendGamePacket(ClientProtocol.U_WASHE_GET_STAGE_REWARD_INFO, builder, userKey.getChannelId(), userKey.getServerId(), userKey.getUserId());
        }
    }
}
